<!DOCTYPE html>
<html><head>
	<meta charset="UTF-8">
	<meta http-equiv="x-UA-Compatible" content="ie=Edge">
   	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Crafty - 2D</title>
	<link type="text/css" rel="stylesheet" href="../craftyjs-site.css">
	<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
	<div id="header-background"> </div>
	<div id="page-frame">
	<div id="header">
		<nav class="navbar">
  			<div class="container-fluid">
  				<div class="navbar-header">
  					<a class="navbar-brand" href="../"> <img class="logo" src="../images/text-logo.png"> </a>
  					
				</div>
				<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
					<ul class="nav navbar-nav">
						<li><a href="../">首页</a></li>
						<li><a href="../getting-started/">快速开始</a></li>
						<li><a href="../documentation/">文档</a></li>
						<li><a href="../api/">API</a></li>
						<li><a href="../components/">组件</a></li>
						<li class="emph"><a href="../#install">下载</a></li>
					</ul>
				</div>
			</div>
		</nav>
	</div>


	<div id="main">
		<div id="content" class="container">
			



<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">事件列表</a></li><li class="category">核心<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-c.html">Crafty.c()</a></li><li><a href="Crafty-clone.html">Crafty.clone()</a></li><li><a href="Crafty-defineField.html">Crafty.defineField()</a></li><li><a href="Crafty-e.html">Crafty.e()</a></li><li><a href="Crafty-extend.html">Crafty.extend()</a></li><li><a href="Crafty-frame.html">Crafty.frame()</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li><li><a href="Crafty-init.html">Crafty.init()</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-pause.html">Crafty.pause()</a></li><li><a href="Crafty-s.html">Crafty.s()</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="AngularMotion.html">AngularMotion</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Crafty-raycast.html">Crafty.raycast()</a></li><li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li><li><a href="Gravity.html">Gravity</a></li><li><a href="GroundAttacher.html">GroundAttacher</a></li><li><a href="Motion.html">Motion</a></li><li><a href="Supportable.html">Supportable</a></li></ul></li><li class="category">动画<ul class="category-list"><li><a href="Crafty-easing.html">Crafty.easing</a></li><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">资源<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset()</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li><li><a href="Crafty-load.html">Crafty.load()</a></li><li><a href="Crafty-paths.html">Crafty.paths()</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li></ul></li><li class="category">音频<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">控制<ul class="category-list"><li><a href="Controllable.html">Controllable</a></li><li><a href="Controls.html">Controls</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Jumper.html">Jumper</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">调试<ul class="category-list"><li><a href="Crafty-error.html">Crafty.error()</a></li><li><a href="Crafty-log.html">Crafty.log()</a></li><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidAreaMap.html">SolidAreaMap</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredAreaMap.html">WiredAreaMap</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">事件<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">游戏循环<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">图形<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasLayer.html">CanvasLayer</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li><li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li><li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li><li><a href="Crafty-sprite.html">Crafty.sprite()</a></li><li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li><li><a href="DOM.html">DOM</a></li><li><a href="DomLayer.html">DomLayer</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Renderable.html">Renderable</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li><li><a href="WebGL.html">WebGL</a></li><li><a href="WebGLLayer.html">WebGLLayer</a></li></ul></li><li class="category">输入<ul class="category-list"><li><a href="AreaMap.html">AreaMap</a></li><li><a href="Button.html">Button</a></li><li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a></li><li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li><li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li><li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li><li><a href="Crafty-selected.html">Crafty.selected</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="MouseDrag.html">MouseDrag</a></li><li><a href="Touch.html">Touch</a></li></ul></li><li class="category">杂项<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">模型<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">场景<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene()</a></li></ul></li><li class="category">舞台<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-scene.html">Crafty.scene()</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">工具<ul class="category-list"><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>2D <span class="page-badge">组件</span></h1><div class="doclet" id="2D"><span class="markdown"><p>该组件用于任何需要绘制在舞台上的实体。</p>
</span><div class="triggered-events"><h4>事件</h4><div class="trigger-list"><dl class="trigger"><dt>Move <span>[<span class="trigger-data"><span class="obj-name">Old position</span><span class="obj-props"> = { _x:Number, _y:Number, _w:Number, _h:Number }</span></span>]</span></dt><dd>当实体移动时触发</dd></dl><dl class="trigger"><dt>Invalidate </dt><dd>当实体需要重绘时触发</dd></dl><dl class="trigger"><dt>Rotate <span>[<span class="trigger-data"><span class="obj-name">Data</span><span class="obj-props"> = { cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}}</span></span>]</span></dt><dd>当实体旋转时触发</dd></dl><dl class="trigger"><dt>Reorder </dt><dd>当实体的 z index 改变时触发</dd></dl></div></div></div><div><h4>属性</h4><ul class="page-toc"><li><a href="#-_globalZ">._globalZ</a></li><li><a href="#-h">.h</a></li><li><a href="#-rotation">.rotation</a></li><li><a href="#-w">.w</a></li><li><a href="#-x">.x</a></li><li><a href="#-y">.y</a></li><li><a href="#-z">.z</a></li></ul><h4>方法</h4><ul class="page-toc"><li><a href="#-_cascade">._cascade()</a></li><li><a href="#-area">.area()</a></li><li><a href="#-attach">.attach()</a></li><li><a href="#-contains">.contains()</a></li><li><a href="#-detach">.detach()</a></li><li><a href="#-intersect">.intersect()</a></li><li><a href="#-isAt">.isAt()</a></li><li><a href="#-mbr">.mbr()</a></li><li><a href="#-move">.move()</a></li><li><a href="#-offsetBoundary">.offsetBoundary()</a></li><li><a href="#-origin">.origin()</a></li><li><a href="#-pos">.pos()</a></li><li><a href="#-shift">.shift()</a></li><li><a href="#-within">.within()</a></li></ul><div class="doclet" id="-_globalZ"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">._globalZ</h2><span class="markdown"><p>当两个实体重叠的时候，一个更大的<code>_globalZ</code>会在另一个上。</p>
</span></div><div class="doclet" id="-h"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.h</h2><span class="markdown"><p>实体的高度。修改后，将自动重新绘制。实际上是一个getter/setter，所以在使用这个值进行计算而不修改它时，使用 <code>._h</code> 属性。</p>
<p>不建议修改这个值，因为会导致canvas的质量有很大的改变，而DOM只会对图像进行修剪。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_setter2d">._setter2d</a></li></ul></div></div><div class="doclet" id="-rotation"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.rotation</h2><span class="markdown"><p>实体在顺时针方向上的旋转状态。
<code>this.rotation = 0</code> 将设置为原来的方向。 <code>this.rotation = 10</code>
在原来方向的基础上顺时针旋转10度。
<code>this.rotation = -10</code> 在原来的方向的基础上逆时针旋转10度,等。</p>
<p>修改后，将自动重新绘制。实际上是一个getter/setter，所以使用这个值进行计算而不改变它时，使用它 <code>._rotation</code> 属性。</p>
<p><code>this.rotation = 0</code> 和 <code>this.rotation = 360</code> 或 <code>720</code> 或
<code>-360</code> 或 <code>36000</code> 等是一样的。所以你可以不断增加或减少连续旋转的角度。(在你达到数百万度之前，数字错误不会发生。)</p>
<p>缺省情况是在其(初始)左上角旋转实体，使用<code>.origin()</code>可以改变这一行为。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_setter2d">._setter2d</a></li><li><a href="#-origin">.origin</a></li></ul></div></div><div class="doclet" id="-w"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.w</h2><span class="markdown"><p>实体的宽度。修改后，将自动重新绘制。实际上是一个getter/setter，所以在使用这个值进行计算而不修改它时，使用<code>._w</code>属性。</p>
<p>不建议修改这个值，因为会导致canvas的质量有很大的改变，而DOM只会对图像进行修剪。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_setter2d">._setter2d</a></li></ul></div></div><div class="doclet" id="-x"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.x</h2><span class="markdown"><p>在舞台上的<code>x</code>位置。修改后，将自动重新绘制。实际上是一个getter/setter，所以在使用这个值进行计算而不修改它时，使用<code>._x</code>属性。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_setter2d">._setter2d</a></li></ul></div></div><div class="doclet" id="-y"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.y</h2><span class="markdown"><p>在舞台上的<code>y</code>位置。修改后，将自动重新绘制。实际上是一个getter/setter，所以在使用这个值进行计算而不修改它时，使用<code>._y</code>属性。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_setter2d">._setter2d</a></li></ul></div></div><div class="doclet" id="-z"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.z</h2><span class="markdown"><p>舞台上的<code>z</code> index。修改后，将自动重新绘制。实际上是一个getter/setter，所以在使用这个值进行计算而不修改它时，使用<code>._z</code>属性。</p>
<p>更高的<code>z</code>值将更接近舞台的前部。更小的<code>z</code>值会更接近背面。一个全局<code>z</code> index是根据其<code>z</code>值和GID(首先创建的实体)生成的。因此，实体将根据创建时的相同<code>z</code>值，自然地维护排序。</p>
<p><code>z</code>需要一个整数, 像 <code>z=11.2</code>是不被允许的。</p>
</span><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-_attr">._attr</a></li></ul></div></div><div class="doclet" id="-_cascade"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">._cascade()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">void </span><span class="sig-noun">._cascade</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">e</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> e </dt><dd><span class="markdown"><p>描述运动的物体</p>
</span></dd></dl></div><span class="markdown"><p>根据特定的动作移动或旋转实体的孩子。这个方法是一个绑定到“Move”的函数的一部分:它在内部用于确保当父进程移动时，子进程也会以相同的方式移动。</p>
</span></div><div class="doclet" id="-area"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.area()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">.area</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">void</span></span><span class="sig-seperator">)</span></code></div><span class="markdown"><p>计算实体的面积</p>
</span></div><div class="doclet" id="-attach"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.attach()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.attach</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Entity </span><span class="sig-noun">obj</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">..</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Entity </span><span class="sig-noun">objN</span></span><span class="sig-seperator">])</span></code><dl class="parameter"><dt> obj </dt><dd><span class="markdown"><p>要连接的子实体(们)</p>
</span></dd></dl></div><span class="markdown"><p>将一个或多个实体设置为子节点，将当前实体(<code>this</code>)作为父节点。当父移动或旋转时，它的子移动或旋转相同的量。(但反之亦然:如果你移动了一个孩子，它就不会移动父母。)当父母被摧毁时，他们的孩子就会被摧毁。</p>
<p>对于任何实体,<code>this._children</code>是子实体对象的数组(如果有的话)，<code>this._parent</code>是它的父实体对象(如果有的话)。</p>
<p>可以附加许多对象，并且可以通过附加来实现对象的层次结构。</p>
</span></div><div class="doclet" id="-contains"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.contains()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.contains</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">w</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">h</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>矩形的X坐标</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>矩形的Y坐标</p>
</span></dd></dl><dl class="parameter"><dt> w </dt><dd><span class="markdown"><p>矩形的宽度</p>
</span></dd></dl><dl class="parameter"><dt> h </dt><dd><span class="markdown"><p>矩形的高度</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.contains</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">rect</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> rect </dt><dd><span class="markdown"><p>一个必须有<code>_x, _y, _w, _h</code>值作为属性的对象。</p>
</span></dd></dl></div><span class="markdown"><p>确定这个矩形是否在当前的实体中。如果该实体被旋转，它的最小外接矩形将被用于测试。</p>
</span></div><div class="doclet" id="-detach"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.detach()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.detach</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-qualifier">Entity </span><span class="sig-noun">obj</span></span><span class="sig-seperator">])</span></code><dl class="parameter"><dt> obj </dt><dd><span class="markdown"><p>分离的实体。省略参数将移除所有附属实体</p>
</span></dd></dl></div><span class="markdown"><p>阻止实体跟随当前实体。没有任何参数的传递将阻止每个实体的连接。</p>
</span></div><div class="doclet" id="-intersect"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.intersect()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.intersect</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">w</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">h</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>矩形的X坐标</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>矩形的Y坐标</p>
</span></dd></dl><dl class="parameter"><dt> w </dt><dd><span class="markdown"><p>矩形的宽度</p>
</span></dd></dl><dl class="parameter"><dt> h </dt><dd><span class="markdown"><p>矩形的高度</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.intersect</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">rect</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> rect </dt><dd><span class="markdown"><p>一个必须有<code>_x, _y, _w, _h</code>值作为属性的对象。</p>
</span></dd></dl></div><span class="markdown"><p>确定这个实体是否与一个矩形相交。如果该实体被旋转，它的最小外接矩形将被用于测试。</p>
</span></div><div class="doclet" id="-isAt"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.isAt()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.isAt</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>点的X坐标</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>点的Y坐标</p>
</span></dd></dl></div><span class="markdown"><p>确定一个点是否包含在实体中。与其他方法不同，对象不能被传递。参数需要x和y值。</p>
<p>给定的点存在的下列情况之一时进行测试:一个与“Mouse”相关的映射区域，与“Collision”相关的hitarea，或者对象的最小外接矩形。</p>
</span></div><div class="doclet" id="-mbr"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.mbr()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Object </span><span class="sig-noun">.mbr</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">mbr</span></span><span class="sig-seperator">])</span></code><dl class="parameter"><dt> mbr </dt><dd><span class="markdown"><p>用作输出的对象</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>一个带有<code>_x</code>, <code>_y</code>, <code>_w</code>, 和 <code>_h</code>属性的对象;如果一个对象被传入，它将被重用而不是创建一个新对象。</p>
</span></dd></dl></div><span class="markdown"><p>返回一个包含该实体最小边界矩形的副本的对象。MBR包含一个旋转的实体的边界。如果实体没有旋转，它将返回它的边界(<code>.pos()</code>)。</p>
</span><div class="note"><span class="markdown"><p><strong>注意:</strong>键有一个下划线前缀。这是由于x、y、w、h属性是setter和getter，用来包装下划线(x、y、w、h)底层属性。</p>
</span></div><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-pos">.pos</a></li></ul></div></div><div class="doclet" id="-move"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.move()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.move</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">dir</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">by</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> dir </dt><dd><span class="markdown"><p>移动方向 (n,s,e,w,ne,nw,se,sw)</p>
</span></dd></dl><dl class="parameter"><dt> by </dt><dd><span class="markdown"><p>在指定的方向移动的量</p>
</span></dd></dl></div><span class="markdown"><p>在指定的方向上(n, s, e, w, ne, nw, se, sw) 移动实体指定像素量的快速方法。</p>
</span></div><div class="doclet" id="-offsetBoundary"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.offsetBoundary()</h2><span class="markdown"><p>将实体的最小外接矩形扩展到指定的数量。</p>
</span><div class="triggered-events"><h4>事件</h4><div class="trigger-list"><dl class="trigger"><dt>BoundaryOffset </dt><dd>当最小外接矩形偏移量改变时触发</dd></dl></div></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.offsetBoundary</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">dx1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">dy1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">dx2</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">dy2</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> dx1 </dt><dd><span class="markdown"><p>将最小外接矩形扩展到左边的量</p>
</span></dd></dl><dl class="parameter"><dt> dy1 </dt><dd><span class="markdown"><p>将最小外接矩形扩展到上边的量</p>
</span></dd></dl><dl class="parameter"><dt> dx2 </dt><dd><span class="markdown"><p>将最小外接矩形扩展到右边的量</p>
</span></dd></dl><dl class="parameter"><dt> dy2 </dt><dd><span class="markdown"><p>将最小外接矩形扩展到下边的量</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.offsetBoundary</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">offset</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> offset </dt><dd><span class="markdown"><p>按这个量将最小外接矩形扩展到各个方向</p>
</span></dd></dl></div><span class="markdown"><p>您很可能会使用这个函数来确保定制的画布渲染超出了实体的正常范围的范围没有被裁剪。</p>
</span></div><div class="doclet" id="-origin"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.origin()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.origin</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>原点的像素值在X轴上偏移</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>Y轴上原点的像素值偏移</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.origin</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">String </span><span class="sig-noun">offset</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> offset </dt><dd><span class="markdown"><p>对齐标识符，它是center, top, bottom, middle, left 和 right的组合。</p>
</span></dd></dl></div><span class="markdown"><p>设置实体旋转时使用的原点。</p>
</span><div class="example"><h4>例子</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">this</span>.origin(<span class="hljs-string">"top left"</span>)
<span class="hljs-keyword">this</span>.origin(<span class="hljs-string">"center"</span>)
<span class="hljs-keyword">this</span>.origin(<span class="hljs-string">"bottom right"</span>)
<span class="hljs-keyword">this</span>.origin(<span class="hljs-string">"middle right"</span>)</code></pre><p>在改变旋转之前应该先设置原点，因为它不具有追溯效力。另外，通过一个对齐标识符设置原点，只在实体的维度被设置之后才起作用。下面的例子如下:</p>
</span></div><div class="example"><h4>例子</h4><span class="markdown"><pre><code class="hljs ">Crafty.e(<span class="hljs-string">"2D"</span>)
      .attr({<span class="hljs-attr">w</span>: <span class="hljs-number">100</span>, <span class="hljs-attr">h</span>: <span class="hljs-number">100</span>})
      .origin(<span class="hljs-string">'center'</span>)
      .attr({<span class="hljs-attr">x</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">rotation</span>: <span class="hljs-number">180</span>});</code></pre></span></div><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-rotation">.rotation</a></li></ul></div></div><div class="doclet" id="-pos"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.pos()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Object </span><span class="sig-noun">.pos</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">pos</span></span><span class="sig-seperator">])</span></code><dl class="parameter"><dt> pos </dt><dd><span class="markdown"><p>用作输出的对象</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>一个带有<code>_x</code>, <code>_y</code>, <code>_w</code>, 和 <code>_h</code>属性的对象;如果一个对象被传入，它将被重用而不是创建一个新对象。</p>
</span></dd></dl></div><span class="markdown"><p>返回一个包含该实体边界的副本(<code>_x</code>, <code>_y</code>, <code>_w</code>, 和 <code>_h</code> 值)的对象。</p>
</span><div class="note"><span class="markdown"><p><strong>注意:</strong>键有一个下划线前缀。这是由于x、y、w、h属性是setter和getter，用来包装下划线(x、y、w、h)底层属性。</p>
</span></div></div><div class="doclet" id="-shift"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.shift()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.shift</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">w</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">h</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>移动X数量</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>Y移动量</p>
</span></dd></dl><dl class="parameter"><dt> w </dt><dd><span class="markdown"><p>扩大的宽度</p>
</span></dd></dl><dl class="parameter"><dt> h </dt><dd><span class="markdown"><p>高度的增加数量</p>
</span></dd></dl></div><span class="markdown"><p>按数量转移或移动实体。相反的方向用负值。</p>
</span></div><div class="doclet" id="-within"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.within()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.within</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">w</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">h</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x </dt><dd><span class="markdown"><p>矩形的X坐标</p>
</span></dd></dl><dl class="parameter"><dt> y </dt><dd><span class="markdown"><p>矩形的Y坐标</p>
</span></dd></dl><dl class="parameter"><dt> w </dt><dd><span class="markdown"><p>矩形的宽度</p>
</span></dd></dl><dl class="parameter"><dt> h </dt><dd><span class="markdown"><p>矩形的高度</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">.within</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">rect</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> rect </dt><dd><span class="markdown"><p>一个必须有<code>_x, _y, _w, _h</code>值作为属性的对象</p>
</span></dd></dl></div><span class="markdown"><p>确定当前的实体是否位于另一个矩形中。</p>
</span></div></div></div></div></div>
			
		</div>
	</div>
	<div class="clearer"></div>
	<div id="footer">
		<div id="contact">
			<a href="https://groups.google.com/forum/#!forum/craftyjs">
				<img src="../images/google.png">
				google groups</a>
			<a href="mailto:starwed@gmail.com">
				<img src="../images/email.png">
				starwed@gmail.com</a>
			<a href="https://github.com/craftyjs/Crafty">
				<img src="../images/github.png">
				github</a>
		</div>
		<ul>
			<li><a href="../">首页</a></li>
				<li><a href="../getting-started/">快速开始</a></li>
				<li><a href="../documentation/">文档</a></li>
				<li><a href="../api/">API</a></li>
				<li><a href="../components/">组件</a></li>
				<li class="emph"><a href="../#install">下载</a></li>
		</ul>
		<p>
			© Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>.
		</p>
	</div>
</div>


</body></html>